package nonre.sgy.gencode.model;

import java.io.File;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;


import nonre.sgy.gencode.GenConfig;
import nonre.sgy.gencode.gen.GenUtil;

public class Service {

	public static void gen(File entityfile){
		
			String entityName = entityfile.getName().split("\\.")[0];
//			System.out.println(entityName);
			
			VelocityContext context = new VelocityContext();
			context.put("genPackage", GenConfig.genPackage);
			context.put("entityName", entityName);
			context.put("camelEntityName", GenUtil.toCamelString(entityName));
			
			try {
				Template t1=Velocity.getTemplate(GenConfig.readPath+"vm/Service.vm");
				File daoDir=new File(GenConfig.genPath+"service");
				if (!daoDir.exists()) {
					daoDir.mkdir();
				}
				File daoFile=new File(daoDir.getAbsolutePath()+"/"+entityName+"Service.java");
				
				GenUtil.genFile(t1, context, daoFile);
				
				//生成daoimpl
				Template t2=GenUtil.getTemplate(GenConfig.readPath+"vm/ServiceImpl.vm");
				File daoImplDir=new File(GenConfig.genPath+"service/impl");
				if (!daoImplDir.exists()) {
					daoImplDir.mkdir();
				}
				File daoImplFile=new File(daoImplDir.getAbsolutePath()+"/"+entityName+"ServiceImpl.java");
				
				GenUtil.genFile(t2, context, daoImplFile);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		
			
	}
	
	public static void main(String[] args) {

	}
}
